package com.ljh.lottery.controller;

import com.ljh.lottery.common.utils.BeanTransUtil;
import com.ljh.lottery.common.utils.JacksonUtil;
import com.ljh.lottery.pojo.request.DrawPrizeRequest;
import com.ljh.lottery.pojo.request.WinningRecordsRequest;
import com.ljh.lottery.pojo.response.CommonResult;
import com.ljh.lottery.pojo.response.WinningRecordsResponse;
import com.ljh.lottery.service.DrawPrizeService;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: Themberfue
 * @date: 2025/4/16 17:01
 * @description:
 */
@RestController
public class DrawPrizeController {
    private static final Logger log = LoggerFactory.getLogger(DrawPrizeController.class);

    @Resource(name = "drawPrizeServiceImpl")
    DrawPrizeService drawPrizeService;

    @PostMapping("/drawPrize")
    public CommonResult<Boolean> drawPrize(@RequestBody @Validated DrawPrizeRequest param) {
        // TODO 1. 打印日志
        log.info("drawPrize DrawPrizeRequest: {}", JacksonUtil.writeValueAsString(param));

        drawPrizeService.drawPrize(param);

        return CommonResult.success(true);
    }

    @PostMapping("/getWinningRecords")
    public CommonResult<List<WinningRecordsResponse>> getWinningRecords(@RequestBody @Validated WinningRecordsRequest param) {
        // TODO 1. 打印日志
        log.info("getWinningRecords WinningRecordsRequest: {}", JacksonUtil.writeValueAsString(param));

        return CommonResult.success(
                drawPrizeService.getWinningRecords(param)
                        .stream()
                        .map(BeanTransUtil::transToWinningRecordsResponse)
                        .toList());
    }

}
